home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / mui38dev-storm / examples / virtual.c < prev    next >
C/C++ Source or Header  |  1999-09-13  |  14KB  |  379 lines

  1. #include "demo.h"
  2.  
  3.  
  4. static const char *Pages[] =
  5. {
  6.     "Big Text Field",
  7.     "Different Objects",
  8.     "Input Accepting Objects",
  9.     "Completly Crazy",
  10.     NULL,
  11. };
  12.  
  13.  
  14. /*FR* Made it all one big line (StormC couldn't handle split lines) */
  15. static const char text1[] = "\33iHello User !\33n\n\nThis could be a very long text and you are looking\nat it through a \33uvirtual group\33n. Please use the\nscrollbars at the right and bottom of the group to\nmove the visible area either vertically or\nhorizontally. While holding down the small arrow\nbutton between both scrollbars, the display will\nfollow your mouse moves.\n\nIf you click somewhere into a \33uvirtual group\33n and\nmove the mouse across one of its borders, the group will\nstart scrolling. If you are lucky and own a middle mouse\nbutton, you may also want to press it and try moving.\n\nWhen the surrounding window is big enough for the\ncomplete virtual group to fit, the scrollers and\nthe move button get disabled.\n\nSince this \33uvirtual group\33n does only contain a\nsingle text object, it's a rather simple example.\nIn fact, virtual groups are a lot more powerful,\nthey can contain any objects you like.\n\nNote to 7MHz/68000 users: Sorry if you find this\nthingy a bit slow. Clipping in virtual groups can\nget quite complicated. Please don't blame me,\nblame your 'out of date' machine! :-)\n\n\33i\33cHave fun, Stefan.\33n";
  16.  
  17.  
  18. APTR MakePage1(VOID)
  19. {
  20.     return
  21.     (
  22.     ScrollgroupObject,
  23. MUIA_Scrollgroup_UseWinBorder, TRUE,
  24.         MUIA_Scrollgroup_Contents, VirtgroupObject,
  25.             VirtualFrame,
  26.             Child, TextObject,
  27.                 MUIA_Background, MUII_TextBack,
  28.                 MUIA_Text_Contents, text1,
  29.                 End,
  30.             End,
  31.         End
  32.     );
  33. }
  34.  
  35. /*FR* Made it all one big line (StormC couldn't handle split lines) */
  36. static const char text2[] = "\33cAs you can see, this virtual group contains a\nlot of different objects. The (virtual) width\nand height of the virtual group are automatically\ncalculated from the default width and height of\nthe virtual groups contents.";
  37.  
  38.  
  39. APTR MakePage2(VOID)
  40. {
  41.     #define img(nr)  ImageObject, MUIA_Image_Spec, nr, End
  42.  
  43.     APTR obj = ScrollgroupObject,
  44.         MUIA_UserData, 42,
  45.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame,
  46.             MUIA_UserData, 42,
  47.             Child, TextObject,
  48.                 TextFrame,
  49.                 MUIA_Background, MUII_TextBack,
  50.                 MUIA_Text_Contents, text2,
  51.                 End,
  52.             Child, HGroup,
  53.                 Child, ColGroup(2), GroupFrameT("Standard Images"),
  54.                     Child, Label("ArrowUp:"    ), Child, img(MUII_ArrowUp    ),
  55.                     Child, Label("ArrowDown:"  ), Child, img(MUII_ArrowDown  ),
  56.                     Child, Label("ArrowLeft:"  ), Child, img(MUII_ArrowLeft  ),
  57.                     Child, Label("ArrowRight:" ), Child, img(MUII_ArrowRight ),
  58.                     Child, Label("RadioButton:"), Child, img(MUII_RadioButton),
  59.                     Child, Label("File:"       ), Child, img(MUII_PopFile    ),
  60.                     Child, Label("HardDisk:"   ), Child, img(MUII_HardDisk   ),
  61.                     Child, Label("Disk:"       ), Child, img(MUII_Disk       ),
  62.                     Child, Label("Chip:"       ), Child, img(MUII_Chip       ),
  63.                     Child, Label("Drawer:"     ), Child, img(MUII_Drawer     ),
  64.                     End,
  65.                 Child, VGroup, GroupFrameT("Some Backgrounds"),
  66.                     Child, HGroup,
  67.                         Child, RectangleObject, TextFrame, MUIA_Background, MUII_BACKGROUND , MUIA_FixWidth, 30, End,
  68.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILL       , MUIA_FixWidth, 30, End,
  69.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOW     , MUIA_FixWidth, 30, End,
  70.                         End,
  71.                     Child, HGroup,
  72.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWBACK , MUIA_FixWidth, 30, End,
  73.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWFILL , MUIA_FixWidth, 30, End,
  74.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWSHINE, MUIA_FixWidth, 30, End,
  75.                         End,
  76.                     Child, HGroup,
  77.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLBACK   , MUIA_FixWidth, 30, End,
  78.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHINEBACK  , MUIA_FixWidth, 30, End,
  79.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLSHINE  , MUIA_FixWidth, 30, End,
  80.                         End,
  81.                     End,
  82.                 End,
  83.             Child, ColGroup(2), GroupFrame,
  84.                 Child, Label1("Gauge:"), Child, GaugeObject, GaugeFrame, MUIA_Gauge_Current, 66, MUIA_Gauge_Horiz, TRUE, End,
  85.                 Child, VSpace(0)       , Child, ScaleObject, End,
  86.                 End,
  87.             End,
  88.         End;
  89.  
  90.     return(obj);
  91. }
  92.  
  93.  
  94. static const char text3[] = "\33cThe above pages only showed 'read only' groups,\nno user actions within them were possible. Of course,\nhandling user actions in a virtual group is not a\nproblem for MUI. As I promised on the first page,\nyou can use virtual groups with whatever objects\nyou want. Here's a small example...\n\nNote: Due to some limitations of the operating system,\nit is not possible to clip gadgets depending on\nintuition.library correctly. This affects the appearence\nof string and proportional objects in virtual groups.\nYou will only be able to use these gadgets when they\nare completely visible.\n\nPS: Also try TAB cycling here!";
  95.  
  96. static const char *CYA_Computer[] = { "Amiga 500","Amiga 600","Amiga 1000 :)","Amiga 1200","Amiga 2000","Amiga 3000","Amiga 4000", "Amiga 4000T", "Atari ST :(", NULL };
  97. static const char *CYA_Printer[]  = { "HP Deskjet","NEC P6","Okimate 20",NULL };
  98. static const char *CYA_Display[]  = { "A1081","NEC 3D","A2024","Eizo T660i",NULL };
  99.  
  100. /*FR* Added StormC compability */
  101. #ifdef __STORM__
  102. STATIC APTR CY_Computer,CY_Printer,CY_Display;
  103. STATIC APTR MT_Computer,MT_Printer,MT_Display;
  104. STATIC APTR LV_Computer;
  105. STATIC APTR BT_Button[12];
  106. #else
  107. static APTR CY_Computer,CY_Printer,CY_Display;
  108. static APTR MT_Computer,MT_Printer,MT_Display;
  109. static APTR LV_Computer;
  110. static APTR BT_Button[12];
  111. #endif
  112.  
  113. APTR MakePage3(VOID)
  114. {
  115.     APTR obj;
  116.  
  117.     obj = ScrollgroupObject,
  118.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame,
  119.             Child, TextObject,
  120.                 TextFrame,
  121.                 MUIA_Background, MUII_TextBack,
  122.                 MUIA_Text_Contents, text3,
  123.                 End,
  124.             Child, VGroup,
  125.                 Child, HGroup,
  126.                     Child, MT_Computer = Radio("Computer:",CYA_Computer),
  127.                     Child, VGroup,
  128.                         Child, MT_Printer = Radio("Printer:",CYA_Printer),
  129.                         Child, VSpace(0),
  130.                         Child, MT_Display = Radio("Display:",CYA_Display),
  131.                         End,
  132.                     Child, VGroup,
  133.                         Child, ColGroup(2), GroupFrameT("Cycle Gadgets"),
  134.                             Child, KeyLabel1("Computer:",'c'), Child, CY_Computer = KeyCycle(CYA_Computer,'c'),
  135.                             Child, KeyLabel1("Printer:" ,'p'), Child, CY_Printer  = KeyCycle(CYA_Printer ,'p'),
  136.                             Child, KeyLabel1("Display:" ,'d'), Child, CY_Display  = KeyCycle(CYA_Display ,'d'),
  137.                             End,
  138.                         Child, LV_Computer =    ListviewObject,
  139.                             MUIA_Listview_ScrollerPos, MUIV_Listview_ScrollerPos_Left,
  140.                             MUIA_Listview_Input, TRUE,
  141.                             MUIA_Listview_List, ListObject, InputListFrame, End,
  142.                             End,
  143.                         End,
  144.                     End,
  145.                 Child, ColGroup(4), GroupFrameT("Button Field"),
  146.                     Child, BT_Button[ 0] = SimpleButton("Button"),
  147.                     Child, BT_Button[ 1] = SimpleButton("Button"),
  148.                     Child, BT_Button[ 2] = SimpleButton("Button"),
  149.                     Child, BT_Button[ 3] = SimpleButton("Button"),
  150.                     Child, BT_Button[ 4] = SimpleButton("Button"),
  151.                     Child, BT_Button[ 5] = SimpleButton("Button"),
  152.                     Child, BT_Button[ 6] = SimpleButton("Button"),
  153.                     Child, BT_Button[ 7] = SimpleButton("Button"),
  154.                     Child, BT_Button[ 8] = SimpleButton("Button"),
  155.                     Child, BT_Button[ 9] = SimpleButton("Button"),
  156.                     Child, BT_Button[10] = SimpleButton("Button"),
  157.                     Child, BT_Button[11] = SimpleButton("Button"),
  158.                     End,
  159.                 End,
  160.             End,
  161.         End;
  162.  
  163.     if (LV_Computer)
  164.         DoMethod(LV_Computer,MUIM_List_Insert,CYA_Computer,-1,MUIV_List_Insert_Bottom);
  165.  
  166.     return(obj);
  167. }
  168.  
  169.  
  170. #define mytxt(txt)\
  171.     TextObject,\
  172.         MUIA_Text_Contents, "\33c"txt,\
  173.         MUIA_Text_SetMax, TRUE,\
  174.         End
  175.  
  176. #define ibt(i)\
  177.     ImageObject,\
  178.         ImageButtonFrame,\
  179.         MUIA_Background, MUII_ButtonBack,\
  180.         MUIA_InputMode , MUIV_InputMode_RelVerify,\
  181.         MUIA_Image_Spec, i,\
  182.         End
  183.  
  184. static char *x4Sex[]     = { "male","female",NULL };
  185. static char *x4Pages[]   = { "Race","Class","Armors","Weapons","Levels",NULL };
  186. static char *x4Races[]   = { "Human","Elf","Dwarf","Hobbit","Gnome",NULL };
  187. static char *x4Classes[] = { "Warrior","Rogue","Bard","Monk","Magician","Archmage",NULL };
  188. static char *x4Weapons[] = { "Staff","Dagger","Sword","Axe","Grenade",NULL };
  189.  
  190. APTR MakePage4(VOID)
  191. {
  192.     APTR bt1,bt2,bt3,bt4,gr,obj,pcy,pgr;
  193.  
  194.     obj = ScrollgroupObject,
  195.         MUIA_Scrollgroup_Contents, ColGroupV(3), VirtualFrame,
  196.             MUIA_Group_Spacing, 10,
  197.             Child, VGroup, GroupFrame,
  198.                 Child, HGroup,
  199.                     Child, HSpace(0),
  200.                     Child, bt1 = ibt(MUII_ArrowUp),
  201.                     Child, HSpace(0),
  202.                     End,
  203.                 Child, HGroup,
  204.                     Child, bt2 = ibt(MUII_ArrowLeft),
  205.                     Child, bt3 = ibt(MUII_ArrowRight),
  206.                     End,
  207.                 Child, HGroup,
  208.                     Child, HSpace(0),
  209.                     Child, bt4 = ibt(MUII_ArrowDown),
  210.                     Child, HSpace(0),
  211.                     End,
  212.                 End,
  213.             Child, mytxt("Ever wanted to see\na virtual group in\na virtual group?"),
  214.             Child, HVSpace,
  215.             Child, mytxt("Here it is!"),
  216.  
  217.             Child, ScrollgroupObject,
  218.                 MUIA_Scrollgroup_Contents, gr = VGroupV, VirtualFrame,
  219.                     Child, ColGroup(6), MUIA_Group_SameSize, TRUE,
  220.                         Child, SimpleButton("One"),
  221.                         Child, SimpleButton("Two"),
  222.                         Child, SimpleButton("Three"),
  223.                         Child, SimpleButton("Four"),
  224.                         Child, SimpleButton("Five"),
  225.                         Child, SimpleButton("Six"),
  226.                         Child, SimpleButton("Eighteen"),
  227.                         Child, mytxt("The"),
  228.                         Child, mytxt("red"),
  229.                         Child, mytxt("brown"),
  230.                         Child, mytxt("fox"),
  231.                         Child, SimpleButton("Seven"),
  232.                         Child, SimpleButton("Seventeen"),
  233.                         Child, mytxt("dog."),
  234.                         Child, SimpleButton("Nineteen"),
  235.                         Child, SimpleButton("Twenty"),
  236.                         Child, mytxt("jumps"),
  237.                         Child, SimpleButton("Eight"),
  238.                         Child, SimpleButton("Sixteen"),
  239.                         Child, mytxt("lazy"),
  240.                         Child, mytxt("the"),
  241.                         Child, mytxt("over"),
  242.                         Child, mytxt("quickly"),
  243.                         Child, SimpleButton("Nine"),
  244.                         Child, SimpleButton("Fifteen"),
  245.                         Child, SimpleButton("Fourteen"),
  246.                         Child, SimpleButton("Thirteen"),
  247.                         Child, SimpleButton("Twelve"),
  248.                         Child, SimpleButton("Eleven"),
  249.                         Child, SimpleButton("Ten"),
  250.                         End,
  251.                     End,
  252.                 End,
  253.  
  254.             Child, mytxt("Do you like it? I hope..."),
  255.             Child, HVSpace,
  256.             Child, mytxt("I admit, it's a\n bit crazy... :-)\nBut it demonstrates\nthe power of\n\33bobject oriented\33n\nGUI design."),
  257.  
  258.             Child, ScrollgroupObject,
  259.                 MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, InnerSpacing(4,4),
  260.                     Child, VGroup,
  261.                         Child, pcy = Cycle(x4Pages),
  262.                         Child, pgr = PageGroup,
  263.                             Child, HCenter(Radio(NULL,x4Races)),
  264.                             Child, HCenter(Radio(NULL,x4Classes)),
  265.                             Child, HGroup,
  266.                                 Child, HSpace(0),
  267.                                 Child, ColGroup(2),
  268.                                     Child, Label1("Cloak:" ), Child, CheckMark(TRUE),
  269.                                     Child, Label1("Shield:"), Child, CheckMark(TRUE),
  270.                                     Child, Label1("Gloves:"), Child, CheckMark(TRUE),
  271.                                     Child, Label1("Helm:"  ), Child, CheckMark(TRUE),
  272.                                     End,
  273.                                 Child, HSpace(0),
  274.                                 End,
  275.                             Child, HCenter(Radio(NULL,x4Weapons)),
  276.                             Child, ColGroup(2),
  277.                                 Child, Label("Experience:"  ), Child, Slider(0,100, 3),
  278.                                 Child, Label("Strength:"    ), Child, Slider(0,100,42),
  279.                                 Child, Label("Dexterity:"   ), Child, Slider(0,100,24),
  280.                                 Child, Label("Condition:"   ), Child, Slider(0,100,39),
  281.                                 Child, Label("Intelligence:"), Child, Slider(0,100,74),
  282.                                 End,
  283.                             End,
  284.                         End,
  285.                     End,
  286.                 End,
  287.  
  288.  
  289.             End,
  290.         End;
  291.  
  292.     if (obj)
  293.     {
  294.         DoMethod(bt1,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,0);
  295.         DoMethod(bt2,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,0);
  296.         DoMethod(bt3,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,9999);
  297.         DoMethod(bt4,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,9999);
  298.  
  299.         DoMethod(pcy,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  300.             pgr,3,MUIM_Set,MUIA_Group_ActivePage,MUIV_TriggerValue);
  301.     }
  302.  
  303.     return(obj);
  304. }
  305.  
  306.  
  307. int main(int argc,char *argv[])
  308. {
  309.     static APTR app,window;
  310.  
  311.     init();
  312.  
  313.     app = ApplicationObject,
  314.         MUIA_Application_Title      , "VirtualDemo",
  315.         MUIA_Application_Version    , "$VER: VirtualDemo 19.5 (12.02.97)",
  316.         MUIA_Application_Copyright  , "©1993, Stefan Stuntz",
  317.         MUIA_Application_Author     , "Stefan Stuntz",
  318.         MUIA_Application_Description, "Show virtual groups.",
  319.         MUIA_Application_Base       , "VIRTUALDEMO",
  320.  
  321.         SubWindow, window = WindowObject,
  322.             MUIA_Window_Title, "Virtual Groups",
  323.             MUIA_Window_ID   , MAKE_ID('V','I','R','T'),
  324.             MUIA_Window_UseRightBorderScroller, TRUE,
  325.             MUIA_Window_UseBottomBorderScroller, TRUE,
  326.             WindowContents, ColGroup(2), GroupSpacing(8),
  327.                 Child, MakePage1(),
  328.                 Child, MakePage2(),
  329.                 Child, MakePage3(),
  330.                 Child, MakePage4(),
  331.                 End,
  332.             End,
  333.         End;
  334.  
  335.  
  336.     if (!app)
  337.         fail(app,"Failed to create Application.");
  338.  
  339.  
  340.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  341.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  342.  
  343.     DoMethod(window,MUIM_Window_SetCycleChain,
  344.         MT_Computer,MT_Printer,MT_Display,
  345.         CY_Computer,CY_Printer,CY_Display,
  346.         LV_Computer,
  347.         BT_Button[ 0],BT_Button[ 1],BT_Button[ 2],BT_Button[ 3],
  348.         BT_Button[ 4],BT_Button[ 5],BT_Button[ 6],BT_Button[ 7],
  349.         BT_Button[ 8],BT_Button[ 9],BT_Button[10],BT_Button[11],
  350.         NULL);
  351.  
  352. /*
  353. ** This is the ideal input loop for an object oriented MUI application.
  354. ** Everything is encapsulated in classes, no return ids need to be used,
  355. ** we just check if the program shall terminate.
  356. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  357. ** from Wait() (or 0). This makes the input loop significantly faster.
  358. */
  359.  
  360.     set(window,MUIA_Window_Open,TRUE);
  361.  
  362.     {
  363.         ULONG sigs = 0;
  364.  
  365.         while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  366.         {
  367.             if (sigs)
  368.             {
  369.                 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  370.                 if (sigs & SIGBREAKF_CTRL_C) break;
  371.             }
  372.         }
  373.     }
  374.  
  375.     set(window,MUIA_Window_Open,FALSE);
  376.  
  377.     fail(app,NULL);
  378. }
  379.